<?php
defined('IN_MAIN') or exit('Invalid Access!');
        
function format_cart_display_for_member($prods, $enable_input=false){
/*
This function format the $prods into bordered table with info refno, title (sub-product if jumpstart), pv, qty, total pv, grand total pv
input $prods must have the format
$prods[index][id]
$prods[index][refno]
$prods[index][prod_type]
$prods[index][title]
$prods[index][pv]
$prods[index][qty]

if $enable_input is true, then the qty is formatted into a select box

using the css style for members only
*/

global $vars;

for($i=0;$i<10;$i++){
 $r_qty[$i]=$i+1;
 $r_qty_d[($i+1)]=$i+1;
}
$total_row=20;

//format each products
for($i=0,$t=count($prods);$i<$t;$i++){
 if($prods[$i]["prod_type"]=="j"){
  $js_prods='';
  for($j=0,$t2=count($prods[$i]["js_prod"]);$j<$t2;$j++){
   $js_prods.="&nbsp;&nbsp;".$prods[$i]["js_prod"][$j]["refno"].", ".$prods[$i]["js_prod"][$j]["title"].", ".__("Qty").__(":")." ".$prods[$i]["js_prod"][$j]["qty"]."<br />\n";
  }
 }
 if($enable_input){
  $this_qty=build_select($r_qty, $r_qty_d, $prods[$i]["qty"], "qty_$i");
 }else{
  $this_qty=$prods[$i]["qty"];
 }
 $prod_row.="
 <tr>
  <td class='center'>".$prods[$i]["refno"]."</td>
  <td>".$prods[$i]["title"].($prods[$i]["prod_type"]=="j"? "<br />\n$js_prods" : "")."</td>
  <td class='number'>".number_format($prods[$i]["pv"], 2)."</td>
  <td class='center'>".$this_qty."</td>
  <td class='number'>".number_format($prods[$i]["pv"] * $prods[$i]["qty"], 2)."</td>".($enable_input? "
  <td class='center'><a href='#' name='delete_item' rel='$i'><img src='".M_URL."/images/icons/delete_button.gif' /></a></td>" : "")."
 </tr>";
 $grand_pv += $prods[$i]["pv"] * $prods[$i]["qty"];
}
//format up to 20 rows
if($enable_input){
 for($i=$i;$i<$total_row;$i++){
  $prod_row.="
  <tr>
   <td>&nbsp;</td>
   <td></td>
   <td></td>
   <td></td>
   <td></td>".($enable_input? "
   <td></td>" : "")."
  </tr>";
 }
}

//the shopping cart
$formatted_prod=
"<table class='shopping-cart'>
 <tr>
  <th>".__("Ref. No.")."</th>
  <th>".__("Title")."</th>
  <th>BV</th>
  <th>".__("Qty")."</th>
  <th>".replace_tag(__("Total <%title%>"), array("<%title%>"=>__($vars["pv_title"])))."</th>".($enable_input? "
  <th>".__("Delete")."</td>" : "")."
 </tr>
 $prod_row
 <tr>
  <td colspan='4' class='bold right'>".replace_tag(__("Grand Total <%title%>"), array("<%title%>"=>__($vars["pv_title"])))."</td>
  <td class='bold number'>".number_format($grand_pv, 2)."</td>
 </tr>
</table>";

return $formatted_prod;
}
?>